package com.example.first;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

import java.util.ArrayList;
import java.util.List;

public class MyListActivity extends ListActivity{
    private  static final String TAG="list";
    Handler handler;
    //private ProgressBar bar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_rate_list);
        List<String> list1= new ArrayList<String>();
        ListView mylist=findViewById(R.id.mylistview);
        /*bar =findViewById(R.id.progressBar);
        mylist.setEmptyView(bar);*/
        for(int i=0;i<100;i++){
            list1.add("item"+i);
        }
        ListAdapter adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list1);
        setListAdapter(adapter);
        handler = new Handler(Looper.myLooper()) {
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.what == 7) {
                    List<String> list2= (List<String>) msg.obj;
                    ListAdapter adapter=new ArrayAdapter<String>(MyListActivity.this,android.R.layout.simple_list_item_1,list2);
                    setListAdapter(adapter);
                    Log.i(TAG, "解析结束");
                    //隐藏bar
                    //bar.setVisibility(View.INVISIBLE);
                }
            }
        };
        //开启线程
        Log.i(TAG,"开启线程");
        MapTask myTask=new MapTask();
        myTask.setHandler(handler);
        Thread t=new Thread(myTask);
        t.start();
    }
}